﻿using Prism.Services.Dialogs;
using System;
using System.Threading.Tasks;
using System.Timers;
using System.Windows;

namespace Base.ModuleBase.Dialogs.ViewModels
{
    public class TipDialogViewModel : DialogViewModelBase
    {
        public TipDialogViewModel()
        {

        }

        public override async void OnDialogOpened(IDialogParameters parameters)
        {
            Title = parameters.GetValue<string>(MessageHelper.Tips_Message);
            var autoClose = parameters.GetValue<bool>(MessageHelper.Tips_AutoClose);
            if (autoClose)
            {
                if (!parameters.TryGetValue(MessageHelper.Tips_AutoCloseTime, out int autoCloseTime) || autoCloseTime <= 0)
                {
                    autoCloseTime = 2000;
                }
                await Task.Delay(autoCloseTime);
                CloseDialog();
            }
        }
        public override void OnDialogClosed()
        {
            base.OnDialogClosed();
            Application.Current.MainWindow.Focus();
        }
    }
}
